package com.ruyuan.seckilling.purchase.async.listener;

import com.ruyuan.seckilling.purchase.async.BasePurchaseListener;
import com.ruyuan.seckilling.purchase.async.PurchaseContext;
import com.ruyuan.seckilling.purchase.async.event.Step5Response;
import com.ruyuan.starter.async.anno.Channel;
import com.ruyuan.starter.async.event.BaseEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 给用户响应抢购成功
 *
 * @author zhonghuashishan
 */
@Slf4j
@Component
@Channel("step5")
public class Step5Listener extends BasePurchaseListener<Step5Response> {

    @Override
    public boolean accept(BaseEvent event) {
        return event instanceof Step5Response;
    }

    @Override
    protected void doThisStep(Step5Response event, PurchaseContext purchaseContext) {
        executorService.execute("step5", () -> {

            log.info("给用户返回抢购成功的响应");

            response(purchaseContext.getAsyncContext(), true, "恭喜您抢购成功");
        });
    }
}
